package com.xxx.exception;


import com.xxx.common.model.RespEnum;
import com.xxx.json.GsonUtil;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ApmException extends RuntimeException{

	private static final long serialVersionUID = -193316907147406110L;
	/**
	 * 枚举信息
	 */
	@Getter
	private RespEnum respEnum;

	public ApmException(){}

	/**
	 * @param respEnum 枚举信息
	 */
	public ApmException(RespEnum respEnum){
		super(respEnum.getDesc());
		if(log.isInfoEnabled()) {
			log.info(respEnum.getCode() + ":" + respEnum.getDesc());
		}
		this.respEnum = respEnum;
	}

	/**
	 *
	 * @param respEnum 枚举信息
	 * @param e 异常
	 */
	public ApmException(RespEnum respEnum, Throwable e){
		super(respEnum.getDesc(),e);
		if(log.isErrorEnabled()) {
			log.error(respEnum.getCode() + ":" + respEnum.getDesc() + "|cause:" + e.getCause() + "|message:" + e.getMessage(), e);
		}
		this.respEnum = respEnum;
	}
	/**
	 *
	 * @param respEnum 枚举信息
	 * @param arguments 参数
	 */
	public ApmException(RespEnum respEnum, Object arguments){
		super(respEnum.getDesc());
		if(log.isInfoEnabled()) {
			log.info(respEnum.getCode() + ":" + respEnum.getDesc() + "|arguments:" + GsonUtil.GsonString(arguments));
		}
		this.respEnum = respEnum;
	}

	/**
	 *
	 * @param respEnum 枚举信息
	 * @param e 异常
	 * @param arguments 参数
	 */
	public ApmException(RespEnum respEnum, Object  arguments, Throwable e){
		super(respEnum.getDesc(),e);
		if(log.isErrorEnabled()) {
			log.error(respEnum.getCode() + ":" + respEnum.getDesc() + "|cause:" + e.getCause() + "|message:" + e.getMessage() + "|arguments:" + GsonUtil.GsonString(arguments), e);
		}
		this.respEnum = respEnum;
	}

	/**
	 *
	 */
	public ApmException(Integer code, String description, Throwable e){
		super(description,e);
		if(log.isErrorEnabled()) {
			log.error(code + ":" + description + "|cause:" + e.getCause() + "|message:" + e.getMessage() + "|arguments:" + e);
		}
	}

	/**
	 *
	 */
	public ApmException(String description, Throwable e){
		super(description,e);
		if(log.isErrorEnabled()) {
			log.error(description + "|cause:" + e.getCause() + "|message:" + e.getMessage() + "|arguments:" + e);
		}
	}



}
